<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>充值订单管理</title>
    <jsp:include page="/resources/inc/head.jsp" flush="true"/>
</head>
<body>
<div id="main">
    <div id="collapseOne" class="panel-collapse collapse">
        <div class="panel panel-default" id="queryHead">
            <div class="panel-body">
                <form id="queryForm" method="post" class="form-horizontal">
                    <label class="col-sm-2 search-control control-label" >订单号：</label>
                    <div class="col-sm-2 search-control">
                        <input type="text" class="form-control" name="orderno" id="orderno"  onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
                               onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}">
                    </div>
                    <label class="col-sm-2 search-control control-label" >支付订单号：</label>
                    <div class="col-sm-2 search-control">
                        <input type="text" class="form-control" name="payOrderId" id="payOrderId"/>
                    </div>
                    <label class="col-sm-2 search-control control-label" >用户ID：</label>
                    <div class="col-sm-2 search-control">
                        <input type="text" class="form-control" name="userid" id="userid"/>
                    </div>
                    <label class="col-sm-2 search-control control-label" >订单状态：</label>
                    <div class="col-sm-2 search-control">
                        <select id="status" name="status" class="form-control">
                            <option value="">请选择--</option>
                        </select>
                    </div>
                    <label class="col-sm-2 search-control control-label" >开始时间：</label>
                    <div class="col-sm-2 search-control">
                        <input type="text" id="begintime" name="begintime"  class="form-control" data-date-format="yyyy-mm-dd" placeholder="开始时间" value="" pattern="yyyy-MM-dd" />
                    </div>
                    <label class="col-sm-2 search-control control-label" >结束时间：</label>
                    <div class="col-sm-2 search-control">
                        <input type="text" id="endtime" class="form-control" name="endtime"  data-date-format="yyyy-mm-dd" placeholder="结束时间" value="" pattern="yyyy-MM-dd" />
                    </div>
                    <div class="col-sm-2 search-control ">
                        <button type="button" class="btn btn-primary" id="search_btn">查询</button>
                        <button type="reset" class="btn btn-primary" id="reset_btn">重置</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div id="toolbar">
        <a class="waves-effect waves-button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne"><i class="zmdi zmdi-search"></i> 高级搜索</a>
    </div>
    <table id="table"></table>
</div>
<jsp:include page="/resources/inc/footer.jsp" flush="true"/>
<jsp:include page="/resources/inc/export.jsp" flush="true"/>

<script>
    var $table = $('#table');
    $(function() {

        $('#begintime,#endtime').datepicker();
        var startTime = new Date();
        startTime.setDate(startTime.getDate()+1);
        var endTime = startTime;

        $('#begintime').val(getPreMonth(getSmpFormatDate(startTime,false)));
        $('#endtime').val(getSmpFormatDate(endTime,false));
        //初始化搜索表单状态
        getSelectOption('PAY_STATUS','status',3);

        // bootstrap table初始化
        $table.bootstrapTable({
            url: '${basePath}/manage/recharge/list',
            height: getNoHeadHeight($('#queryHead').height),
            detailFormatter: 'detailFormatter',
            paginationLoop: false,
            silentSort: false,
            smartDisplay: false,
            escape: true,
            searchOnEnterKey: true,
            maintainSelected: true,
            toolbar: '#toolbar',               //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            sortable: true,                     //是否启用排序
            sortOrder: "asc",                   //排序方式
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
            pageSize: 10,                     //每页的记录行数（*）
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            search: false,                      //是否显示表格搜索
            strictSearch: true,
            showColumns: true,                  //是否显示所有的列（选择显示的列）
            showRefresh: true,                  //是否显示刷新按钮
            minimumCountColumns: 2,             //最少允许的列数
            clickToSelect: true,                //是否启用点击选中行
            showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
            cardView: false,                    //是否显示详细视图
            detailView: false,                  //是否显示父子表
            idField: 'id',
            toolbar: '#toolbar',
            queryParams : function(params) {
                return splitFormSerializeValue('queryForm',params);
            },
            columns: [
                {field: 'ck', checkbox: true},
                {field: 'orderno', title: '订单号'},
                {field: 'payorderid', title: '支付订单号'},
                {field: 'userid', title: '用户ID'},
                {field: 'amount', title: '面额(元)'},
                {field: 'payamount', title: '实付金额(元)'},
                {field: 'discountedamount', title: '折扣金额(元)'},
                {field: 'prepaidbalance', title: '充值前余额(元)'},
                {field: 'status', title: '订单状态',formatter: function (value, row, index) {
                    return getDictText("PAY_STATUS",value);
                }},
                {field: 'paytype', title: '支付方式',formatter: function (value, row, index) {
                    return getDictText("PAY_METHOD",value);
                }},
                {field: 'createtime', title: '创建时间',formatter:'detailLongDateTimeFormatter'},
                {field: 'paysucctime', title: '支付成功时间',formatter:'detailLongDateTimeFormatter'},
                {field: 'description', title: '描述'}
            ]
            <shiro:hasPermission name="business:recharge:export">
            ,
            //导出excel表格设置
            showExport: phoneOrPc(),              //是否显示导出按钮(此方法是自己写的目的是判断终端是电脑还是手机,电脑则返回true,手机返回falsee,手机不显示按钮)
            exportDataType: "basic",              //basic', 'all', 'selected'.
            exportTypes:['excel','xlsx'],	    //导出类型
            exportOptions:{
                //ignoreColumn: [0,0],            //忽略某一列的索引
                fileName: '充值订单数据导出',              //文件名称设置
                excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],
                //onMsoNumberFormat: DoOnMsoNumberFormat
            }
            //导出excel表格设置
            </shiro:hasPermission>
        });

        //查询按钮事件
        $('#search_btn').click(function() {
            $('#table').bootstrapTable('refresh', {
                //得到查询的参数
                queryParams : function(params) {
                    return splitFormSerializeValue('queryForm',params);
                },
                url : '${basePath}/manage/recharge/list'
            });
        })
        //重置按钮事件
        $("#reset_btn").click(function(){
            $("#queryForm").resetForm();
        });

    });

    function getPreMonth(date) {
        var arr = date.split('-');
        var year = arr[0]; //获取当前日期的年份
        var month = arr[1]; //获取当前日期的月份
        var day = arr[2]; //获取当前日期的日
        var days = new Date(year, month, 0);
        days = days.getDate(); //获取当前日期中月的天数
        var year2 = year;
        var month2 = parseInt(month) - 1;
        if (month2 == 0) {
            year2 = parseInt(year2) - 1;
            month2 = 12;
        }
        var day2 = day;
        var days2 = new Date(year2, month2, 0);
        days2 = days2.getDate();
        if (day2 > days2) {
            day2 = days2;
        }
        if (month2 < 10) {
            month2 = '0' + month2;
        }
        var t2 = year2 + '-' + month2 + '-' + day2;
        return t2;
    }
</script>
</body>
</html>